<template>
	<view style="" class="centen">
		<view class="video-empty" v-if="dataList.length === 0">
			<u-empty mode="history" text="暂无任务视频" use-slot>
				<button class="empty-btn" @click="gohome">立即制作</button>
			</u-empty>
		</view>
		<scroll-view scroll-y="true" class="scroll-Y scroll_list" @scrolltolower="lower"
			:style="{ height: 'calc(100vh - 108px)' }" v-else>
			<view class="video-list">
				<view class="video-item" v-for="(item,index) in dataList" :key="index" @click="videoDetail(3,item.id)">
						<view class="video-url">
							<image style="width: 100%; height: 100%;" mode='aspectFill' :src="item.coverImg"></image>
							<!-- 左下角类型标签 -->
							<view class="video-type-badge">{{item.taskType==1?'图片':'视频'}}</view>
							<!-- 右下角时长标签 -->
							<view class="video-duration-badge">{{durationfn(item.videoDuration)}}</view>
						</view>
						<view class="video-info">
							<view class="video-title">{{item.title}}</view>
							<view class="video-date">{{item.insertTime}}</view>
						</view>
					</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		judgetoken
	} from '../../utils/utils.js'
	export default {
		data() {
			return {
				query: {
					pageNum: 1,
					pageSize: 10
				},
				// dataList:[],
				dataList: [
				// 	{
				// 	videoUrl: "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400",
				// 	videoName: "山间河流自然摄像",
				// 	videoDate: "11点30分"
				// }, {
				// 	videoUrl: "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400",
				// 	videoName: "最新科技产品发布会全程回顾",
				// 	videoDate: "2025-10-01"
				// },
				],
			};
		},
		components: {

		},

		onload() {

		},
		mounted() {
			this.workslistfn()
		},
		watch: {

		},
		methods: {
			durationfn(ms) {
				// 将毫秒转换为秒
				let seconds = Math.floor(ms / 1000);
			
				// 计算分钟和剩余的秒数
				let minutes = Math.floor(seconds / 60);
				let remainingSeconds = seconds % 60;
			
				// 格式化输出 MM:SS
				return `${minutes < 10 ? '0' + minutes : minutes}:${remainingSeconds < 10 ? '0' + remainingSeconds : remainingSeconds}`;
			},
			gohome(){
				uni.reLaunch({
					url: '/pages/homepage/page_home'
				});
			},
			lower() {
				this.query.pageNum++
				this.workslistfn()
			},
			workslistfn() {
				if(!judgetoken()){
					return
				}
				this.$request(`/works/listByPage`, 'post', this.query).then(
					res => {
						this.dataList = res.data.data.records?this.dataList.concat(res.data.data.records):[]
					})
			},
			videoDetail(type,id) {
				const obj ={
					type:type,
					id:id
				}
				// 传值 当前卡片的状态
				uni.navigateTo({
					url: '/pages/video/video_detail?type='  + encodeURIComponent(JSON.stringify(obj))
				})
			}
		}
	};
</script>

<style scoped>
	/* 适配小程序的视频列表样式 */

	.centen {
		min-height: calc(100vh - 108px);
		padding: 0px 12px;
		box-sizing: border-box;
	}

	.video-empty {
		width: 100%;
		min-height: 60vh;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.empty-btn {
		border-radius: 24px;
		font-size: 16px;
		font-weight: 500;
		margin-top: 16px;
		color: #fff;
		background-color: #f94222;
		padding:0px 24px;
	}

	button::after {
		border: none;
	}

	.video-list {
		width: 100%;
		height: auto;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		gap: 12px;
	}

	.video-item {
		width: calc(50% - 6px);
		background: #fff;
		border-radius: 12px;
		overflow: hidden;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
	}

	.video-url {
		width: 100%;
		/* 调整为更合适的宽高比，使图片更高 */
		aspect-ratio: 3 / 3;
		position: relative;
		overflow: hidden;
		border-radius: 12px 12px 0 0;
	}

	.video-url image {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}

	/* 左下角类型标签 */
	.video-type-badge {
		position: absolute;
		bottom: 8px;
		left: 8px;
		background-color: rgba(249, 66, 34, 0.9);
		color: white;
		font-size: 11px;
		font-weight: 500;
		padding: 3px 8px;
		border-radius: 4px;
		z-index: 10;
	}

	/* 右下角时长标签 */
	.video-duration-badge {
		position: absolute;
		bottom: 8px;
		right: 8px;
		background-color: rgba(0, 0, 0, 0.7);
		color: white;
		font-size: 11px;
		font-weight: 500;
		padding: 3px 6px;
		border-radius: 4px;
		z-index: 10;
	}

	.video-info {
		width: 100%;
		padding: 10px 12px 12px 12px;
		box-sizing: border-box;
	}

	/* 优化标题样式 */
	.video-info .video-title {
		font-size: 28rpx;
		font-weight: 600;
		color: #333333;
		line-height: 1.4;
		min-height: 40px;
		max-height: 40px;
		overflow: hidden;
		word-break: break-word;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		margin-bottom: 6px;
	}

	/* 生成时间 */
	.video-date {
		font-size: 11px;
		color: #888888;
	}
</style>